package com.cyj.dream.admin.controller.admin.system;

import com.cyj.dream.admin.service.system.LoginService;
import com.cyj.dream.core.aspect.annotation.ResponseResult;
import com.cyj.dream.core.aspect.annotation.log.LogRecord;
import com.cyj.dream.core.aspect.enums.OperatorType;
import com.cyj.dream.core.constant.Constant;
import com.cyj.dream.core.util.captcha.CaptchaUtils;
import com.cyj.dream.security.annotation.AnonymousAccess;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;


/**
 * @Description: 登录控制器
 * @BelongsProject: fckj-restaurant
 * @BelongsPackage: com.fckj.fckjrestaurant.controller.admin.systems
 * @Author: ChenYongJia
 * @CreateTime: 2021-05-29 15:12
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
@Slf4j
@RestController
@ResponseResult
@Api(value = "logins", tags = "登录控制器")
@RequestMapping(value = "/pc/logins", name = "登录控制器")
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 获取登陆验证图片和验证码
     *
     * @param response
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @date 2021/5/29 15:36
     * @author ChenYongJia
     * @version 1.0
     */
    @AnonymousAccess
    @ApiOperation(value = "获取登陆验证图片和验证码", httpMethod = "GET")
    @LogRecord(title = "获取登陆验证图片和验证码", operatetype = OperatorType.SELECT)
    @RequestMapping(value = "/getImgAndCode", name = "获取登陆验证图片和验证码", method = RequestMethod.GET)
    public Map<String, Object> getImgAndCode(HttpServletResponse response) {
        log.info("进入登录控制器--获取登陆验证图片和验证码");
        return CaptchaUtils.getImg();
    }

    /**
     * 前端获取公钥
     *
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @date 2021/6/7 14:41
     * @author ChenYongJia
     * @version 1.0
     */
    @AnonymousAccess
    @ApiOperation(value = "前端获取公钥", httpMethod = "GET")
    @LogRecord(title = "前端获取公钥", operatetype = OperatorType.SELECT)
    @RequestMapping(value = "/getPublicKey", name = "前端获取公钥", method = RequestMethod.GET)
    public Map<String, Object> getPublicKey() {
        log.info("进入登录控制器--前端获取公钥");
        Map<String, Object> map = new HashMap<>(Constant.INITIAL_CAPACITY);
        map.put("publicKey", loginService.getPublicKey());
        return map;
    }

}
